<?php
	include("../include/init.php");//将配置文件全部加载进来
	include("../include/check_login.php");//登录

	$insert = new sql_class("product");

	$product_id = isset($_GET['product_id']) ? $_GET['product_id'] : 0;
	if(!$product_id){
		show_msg("请重新选择","pro_list.php");
		exit;
	}

	$pro_list = $insert->select("product_id = $product_id")->getOne();

	if($_POST){
		$data = array(
					"product_name"=>$_POST['product_name'],
					"product_price"=>$_POST['product_price'],
					"product_disc"=>$_POST['product_disc'],
					"product_time"=>strtotime($_POST['product_time']),
					"product_date"=>$_POST['product_date'],
					"product_promise"=>$_POST['product_promise'],
					"product_address"=>$_POST['product_address'],
					"product_desc"=>$_POST['product_desc'],
					"product_content"=>$_POST['product_content'],
				);
		
		if($_FILES['product_img']['size'] > 0 ){
			$path = DIR."/uploads/";
			$filename = uploads("product_img",1048576,$path);
			$data['product_img'] = "uploads/".$filename;
		}

		$where = "product_id = $product_id";
		$affect_id = $insert->update($data,$where);
		if($affect_id){
			show_msg("更新产品成功","pro_list.php");
			exit;
		}else{
			show_msg("更新产品失败","pro_edit.php?product_id = $product_id");
			exit;
		}
	}

	$smarty->assign("pro_list",$pro_list);
	$smarty->display("admin/pro_edit.html");//连接index.html



?>